<?php

class Tatu {
	
	var $config;
	
	var $db = null;
	var $templates_dir = 'templates/';
	var $output; 
	
	function Tatu() {
		$this->config = get_config();	
		//$this->templates_dir = ABSPATH . $templates_dir;
	}  
	
	/**
	 * 创建数据库连接
	 * @return void
	 */
	function database() {
		$this->db = load_class('db');
	}
	
	/**
	 * 加载库文件
	 * @return void
	 */
	function lib() {
		$lib_list = func_get_args();
		foreach( $lib_list as $lib ) {
			$this->$lib = load_class( $lib );	
		}
	}

	/**
	 * 加载帮助文件
	 * @return unknown_type
	 */
	function helper() {
		$helper_list = func_get_args();
		foreach( $helper_list as $helper  ) {
			require_once( dirname(__FILE__) . '/helpers/'. $helper .'_helper.php' );	
		}
	}
	
	/**
	 * 获取配置信息
	 * @param $name
	 * @return string
	 */
	function get_config($name) {
		return isset( $this->config[$name] ) ? $this->config[$name] : null;
	}
	
	function view($viewer, $data=array(), $is_return = FALSE) {
		extract($data);
		ob_start();                    
       	include( ABSPATH . $this->templates_dir . $viewer . '.tpl.php' );  
       	$contents = ob_get_contents();
       	ob_end_clean();
		if( $is_return ) {
			return $contents;
		}
		else {
			$this->output = $contents;
			return TRUE;
		}
	}

}


?>